package com.i2silly.wxbot.quartz.job;

import com.i2silly.wxbot.config.TempCache;
import com.i2silly.wxbot.server.RobotServer;
import com.i2silly.wxbot.utils.PubUtils;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @program: wx-bot
 * @description：获取群成员
 * @author: pzhongqiang@linewell.com
 * @date: 2020年12月15日 20:20:13
 */
@Component
@DisallowConcurrentExecution
public class GetChatroomJob implements Job {

    @Autowired
    private RobotServer server;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        TempCache cache = server.getCache();
        Set<String> chatroomIds = cache.getChatroomIds();
        if (PubUtils.isNotEmpty(chatroomIds)) {
            for (String chatroomId : chatroomIds) {
                server.sendGetChatroomMember(chatroomId);
            }
        }
    }
}
